from typing import Union

from helper.texter.Language import language_py
from helper.texter.Replacer import b0
from helper.texter.TextBlock import CodeBlock, get_line_block, get_assign_block, get_args_block, get_empty_block


def get_py_block(
        template: str,
        *replace_list: Union[str, CodeBlock],
):
    return CodeBlock.get_block(language_py, template, *replace_list)


def get_py_empty_block(
        *replace_list: Union[str, CodeBlock],
):
    return get_py_block("", *replace_list)


def get_py_line_block(
        v: Union[str, CodeBlock] = "",
):
    cb = get_line_block(
        v,
    )
    cb.language = language_py
    return cb


def get_py_arr_block(
        v: Union[str, CodeBlock],
):
    return get_py_block(
        f"[{b0}]",
        v
    )


class PyBlockTask:
    @staticmethod
    def task1_print_b_list_block(
            bs_size: int = 16,
    ):
        def get_assign_b_block(index: int):
            return get_line_block(
                get_assign_block(
                    f"b{index}",
                    f"bs[{index}]"
                )
            )

        if_l_strip = True
        for i in range(bs_size):
            if i > 0:
                if_l_strip = False
            get_assign_b_block(i).print_code(if_l_strip=if_l_strip, )

        bs_str = []
        for i in range(bs_size):
            bs_str.append(f"b{i}")

        args_block = get_args_block(*bs_str)

        get_line_block(get_empty_block(
            "# from helper.coder.Replacer import bs, ",
            args_block,
        )).print_code(if_l_strip=False, )


if __name__ == '__main__':
    PyBlockTask.task1_print_b_list_block()
